#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
创建测试数据用于验证空目录扫描功能
"""

import os
import shutil
import tempfile

def create_test_structure():
    """创建测试目录结构"""
    # 创建测试根目录
    test_root = os.path.join(os.getcwd(), 'test_empty_dirs')
    
    # 如果已存在则删除
    if os.path.exists(test_root):
        shutil.rmtree(test_root)
    
    # 创建测试结构
    os.makedirs(test_root)
    
    # 创建空目录
    empty_dirs = [
        'empty_dir_1',
        'empty_dir_2', 
        'subfolder/empty_subdir_1',
        'subfolder/empty_subdir_2',
        'deep/level1/level2/empty_deep'
    ]
    
    for empty_dir in empty_dirs:
        empty_path = os.path.join(test_root, empty_dir)
        os.makedirs(empty_path, exist_ok=True)
    
    # 创建非空目录
    non_empty_dirs = [
        'non_empty_1',
        'non_empty_2',
        'subfolder/non_empty_sub'
    ]
    
    for non_empty_dir in non_empty_dirs:
        non_empty_path = os.path.join(test_root, non_empty_dir)
        os.makedirs(non_empty_path, exist_ok=True)
        # 在非空目录中创建文件
        with open(os.path.join(non_empty_path, 'test.txt'), 'w') as f:
            f.write('This is a test file')
    
    print(f"测试目录结构已创建: {test_root}")
    print("目录结构:")
    for root, dirs, files in os.walk(test_root):
        level = root.replace(test_root, '').count(os.sep)
        indent = ' ' * 2 * level
        print(f"{indent}{os.path.basename(root)}/")
        subindent = ' ' * 2 * (level + 1)
        for file in files:
            print(f"{subindent}{file}")
        for dir in dirs:
            if not os.listdir(os.path.join(root, dir)):
                print(f"{subindent}{dir}/ (空)")
    
    return test_root

if __name__ == '__main__':
    test_root = create_test_structure()
    print(f"\n测试目录已创建: {test_root}")
    print("您可以在GUI界面中使用此目录来测试空目录扫描功能。")
    print("预期的空目录:")
    print("- empty_dir_1")
    print("- empty_dir_2") 
    print("- subfolder/empty_subdir_1")
    print("- subfolder/empty_subdir_2")
    print("- deep/level1/level2/empty_deep")